<?php 
require_once 'sesi_login.php';
require_once 'konfigurasi.php';

fungsi('pengguna');

define('PAGE', 'Admin Input Nilai');
define('PAGE_ICO', 'icon-stats');
define('PAGE_URL', 'admin_input_nilai.php');

panggil_header();
koneksi_buka();

$kelas = "";
$materi = "";

if(isset($_POST['kelas'])){
	$kelas = $_POST['kelas'];
}

if(isset($_POST['materi'])){
	$materi = $_POST['materi'];
}

$tahun = date("Y");          

if($materi!=""){
	$text_q_nilai = "select * from nilai a left join siswa b on a.siswa=b.id where b.kelas=$kelas and a.materi=$materi";
	if(!mysql_fetch_array(mysql_query($text_q_nilai))){
			$text_q_siswa = "select * from siswa where kelas=$kelas";
			$q_siswa = mysql_query($text_q_siswa);
			while($dt_siswa = mysql_fetch_array($q_siswa)){
				$insert_nilai = mysql_query("insert into nilai (siswa, materi, tahun_ajaran) values(".$dt_siswa['id'].", $materi, $tahun)");
			}
		

	}
}   


$text_q_nilai = "select 
				IFNULL(c.id, '-') as n_id, 
				IFNULL(c.tugas, '-') as n_tugas, 
				IFNULL(c.uts, '-') as n_uts, 
				IFNULL(c.uas, '-') as n_uas, 
				IFNULL(c.latihan, '-') as n_latihan,
				IFNULL(c.akhir, '-') as n_akhir,
				IFNULL(c.harian, '-') as n_harian, 
				a.nis as s_nis,
				a.nama as s_nama, d.nama as m_nama, b.nama as k_nama,
				a.id as s_id, d.id as m_id 
				from siswa a
				left join kelas b on a.kelas = b.id
				left join nilai c on a.id = c.siswa
				left join materi d on d.tipe_kelas = b.tipe 
				where d.id like'%$materi%' and b.id like'%$kelas%'";

?>

	<div class="content">
					
		<div class="page-header">
			<div class="icon">
				<span class="ico-arrow-right"></span>
			</div> 
			<h1> Input Nilai<small>SDN I</small></h1>
		</div>
		

		<div class="row-fluid">
			<div class="span12">                

				<div class="block">
					<div class="head">                                
						<h2>Input Nilai</h2>
						<ul class="buttons">             
							<li><a href="#" onClick="source('form_pa'); return false;"><div class="icon"><span class="ico-info"></span></div></a></li>
						</ul>                                                                  
					</div>                                    
					<form id="validate" method="post" action="admin_input_nilai.php">
                	<div class="data-fluid">
						<div class="row-form">
							<div class="span3">Kelas</div>
							<div class="span9">
								<select name="kelas" class="select" style="width: 100%;">
									<?php 
									$text_q_kelas = "select * from kelas";
									$q_kelas = mysql_query($text_q_kelas);
									while($dt_kelas = mysql_fetch_array($q_kelas)){?>
										<option value="<?php echo $dt_kelas['id'];?>"><?php echo $dt_kelas['nama'];?></option>
									<?php }?>                                        
								</select>
							</div>
						</div>       
						<div class="row-form">
							<div class="span3">Materi</div>
							<div class="span9">
								<select name="materi" class="select" style="width: 100%;">
									<?php 
									$text_q_materi = "select * from materi";
									$q_materi = mysql_query($text_q_materi);
									while($dt_materi = mysql_fetch_array($q_materi)){?>
										<option value="<?php echo $dt_materi['id'];?>"><?php echo $dt_materi['nama'];?></option>
									<?php }?>                                        
								</select>
							</div>
						</div>                  
						
						<div class="row-form">
							<div class="span3"></div>
							<div class="span9">                       
								<input type="submit" class="btn btn-primary" value="Edit"/> 		
								<input type="reset" class="btn btn-warning" value="Batal"/>       
							</div>   
						</div>
					</div>
				</form>        
				</div>
			</div>  
		</div> 
		<?php if($materi!=""){?>
			<div class="row-fluid">
			<div class="span12">
				<div class="block">
					<div class="head purple">
						<div class="icon"><span class="ico-location"></span></div>
						<h2>Input Nilai</h2>     
						<ul class="buttons">
							<li><a href="#" onClick="source('table_hover'); return false;"><div class="icon"><span class="ico-info"></span></div></a></li>
						</ul>                                                          
					</div>                
					<div class="data-fluid">
						<table id="table-editable" cellpadding="0" cellspacing="0" width="100%" class="table fpTable lcnp">
							<thead>
								<tr>
									<th width="10%">
										No
									</th>
									<th width="10%">
										NIS
									</th>
									<th width="20%">
										Nama
									</th>
									<th width="10%">
										Latihan
									</th>
									<th width="10%">
										Harian
									</th>
									<th width="10%">
										UTS
									</th>
									<th width="10%">
										UAS
									</th>
									<th width="10%">
										Akhir
									</th>
								</tr>
							</thead>
							<tbody>
							<?php
								$i=1;
								$q_nilai = mysql_query($text_q_nilai);
								while($dt_nilai = mysql_fetch_array($q_nilai)){
							?>
								<tr data-siswa="<?php echo $dt_nilai['s_id'];?>" data-materi="<?php echo $dt_nilai['m_id'];?>" id="<?php echo $dt_nilai['n_id'];?>">
									<td>
										<?php echo $i; $i++;?>
									</td>
									<td>
										<?php echo $dt_nilai['s_nis'];?>
									</td>
									<td>
										<?php echo $dt_nilai['s_nama'];?>
									</td>
									<!--
									<td class="editable-column">
									-->
									<td>
										<?php echo $dt_nilai['n_latihan'];?>
									</td>
									<td>
										<?php echo $dt_nilai['n_harian'];?>
									</td>
									<td>
										<a href="admin_input_nilai_uts.php?nilai=<?php echo $dt_nilai['n_id']?>"><?php echo $dt_nilai['n_uts'];?></a>
									</td>
									<td>
										<?php echo $dt_nilai['n_uas'];?>
									</td>
									<td>
										<?php echo $dt_nilai['n_akhir'];?>
									</td>
								</tr>
							<?php
								}
							?>

								
							</tbody>
						</table>
					</div>  
					
								 
				</div>
			</div>
		<? }?>
		
	</div>


</div>
<div class="dialog" id="source" style="display: none;" title="Source"></div>

<?php
panggil_footer();
?>
